pub fn convert_base(num_str: &str, to_base: u32) -> String {
    // 分割输入字符串，解析数字和进制
    let parts: Vec<&str> = num_str.trim().split('(').collect();
    if parts.len() != 2 {
        return String::from("Invalid input format");
    }

    let number_part = parts[0].trim();
    let base_part = parts[1].trim().trim_end_matches(')');

    // 将原进制转换为 u32
    let from_base = match base_part.parse::<u32>() {
        Ok(base) if (2..=16).contains(&base) => base,
        _ => return String::from("Invalid base"),
    };

    // 将输入的字符串转换为10进制数字
    let decimal_value = match u32::from_str_radix(number_part, from_base) {
        Ok(value) => value,
        Err(_) => return String::from("Invalid number"),
    };

    // 将10进制数字转换为目标进制的字符串
    match to_base {
        2..=16 => format_number_in_base(decimal_value, to_base),
        _ => String::from("Unsupported base"),
    }
}

// 辅助函数，将数字转换为指定进制的字符串
fn format_number_in_base(mut num: u32, base: u32) -> String {
    if num == 0 {
        return "0".to_string();
    }

    let mut result = String::new();
    while num > 0 {
        let remainder = num % base;
        let digit = if remainder < 10 {
            (b'0' + remainder as u8) as char
        } else {
            (b'a' + (remainder - 10) as u8) as char
        };
        result.insert(0, digit);
        num /= base;
    }

    result
}